** Table 4: ECB access: Introduction of ECB tiering system
clear

** Loading data
*cd // *Your directory path goes here* //
import excel .\Data\GC_DailyAverages_Pseudo.xlsx, firstrow allstring

* Step 1: Organize the data:
gen dateSTATA = date(substr(refdate,1,11),"MDY")
format dateSTATA %td
drop refdate
gen year = year(dateSTATA)
gen month = month(dateSTATA)

destring volweightedrate volsum ecbaccesslender, replace
encode basket, gen(basketcat)
drop basket
label define order  1 ON  2 TN  3 SN
encode term, gen(termcat) label(order)
drop term

gen QE = 0
*start of QE, see: https://www.ecb.europa.eu/mopo/implement/app/html/index.en.html#pspp
replace QE = 1 if dateSTATA > date("08.03.2015","DMY") 

egen panelid = group(basketcat termcat ecbaccesslender)
xtset panelid dateSTATA

* Step 2: Add information on EONIA
* download daily data from, for example, Bloomberg / Thomson Reuters and replace code below:
gen EONIA=0.5 // create pseudodata

* Step 4: Calculate changes:
bysort panelid (dateSTATA): gen delrGC = log(volweightedrate[_n]/volweightedrate[_n-1])
bysort panelid (dateSTATA): gen delrGCtm1 = log(volweightedrate[_n-1]/volweightedrate[_n-2])
bysort panelid (dateSTATA): gen delMMRate = log(EONIA[_n]/EONIA[_n-1])

* Step 5: Focus on the two ECB maintenance periods preceding the ECB tiering introduction as well as the two ECB maintenance periods thereafter (August 2019 to January 2020)
* Maintenace periods: https://www.ecb.europa.eu/press/pr/date/2018/html/ecb.pr180711.en.html
* Tiering announcement: https://www.ecb.europa.eu/press/pr/date/2019/html/ecb.pr190912_2~a0b47cd62a.en.html
keep if (dateSTATA >= date("31.07.2019","DMY") & dateSTATA <= date("29.10.2019","DMY")) | (dateSTATA >= date("30.10.2019","DMY") & dateSTATA <= date("28.01.2020","DMY"))
gen Tiering = 0
replace Tiering = 1 if dateSTATA > date("29.10.2019","DMY")
drop if (dateSTATA == date("17.09.2019","DMY") | dateSTATA == date("29.10.2019","DMY") | dateSTATA == date("17.12.2019","DMY") | dateSTATA == date("28.01.2020","DMY"))

* Step 6: Calculate additional regression inputs:

gen delMMRate_Tier = delMMRate*Tiering
gen delMMRate_Acc = delMMRate*ecbaccesslender
gen delMMRate_Acc_Tier = delMMRate*ecbaccesslender*Tiering


** Regressions

* All
eststo clear
sort termcat
eststo R3a, title("All"): reghdfe delrGC delMMRate Tiering delMMRate_Tier ecbaccesslender delMMRate_Acc delMMRate_Acc_Tier delrGCtm1, absorb(month termcat) vce(robust) nocons

* Core
keep if (country=="DE"|country=="FR"|country=="BE"|country=="NL"|country=="FI"|country=="AT")
sort termcat
eststo R2a, title("Core"): reghdfe delrGC delMMRate Tiering delMMRate_Tier ecbaccesslender delMMRate_Acc delMMRate_Acc_Tier delrGCtm1, absorb(month termcat)  vce(robust) nocons

* Germany
keep if (country=="DE")
sort termcat
eststo R1a, title("DE"): reghdfe delrGC delMMRate Tiering delMMRate_Tier ecbaccesslender delMMRate_Acc delMMRate_Acc_Tier delrGCtm1, absorb(month termcat) vce(robust) nocons
